package com.demo.pattern.single;

// 懒汉式，双重检查，线程安全,同步方法
public class DemoTest6 {
    public static void main(String[] args) {
        System.out.println(Single3.getInstance() == Single3.getInstance());
    }
}

class Single6 {
    // 私有构造方法，外部不能new
    private Single6() {
    }

    public static volatile Single6 instance;

    // 解决线程安全和懒加载问题
    public static synchronized Single6 getInstance() {
        if (instance == null) {
            synchronized (Single6.class) {
                if (instance == null) {
                    instance = new Single6();
                }
            }
        }
        return instance;
    }
}